A device may examine, and perhaps modify, an original series of data bits. For example, an original series of data bits might be examined to determine if the series includes a predetermined pattern of data bits. If the pre-determined pattern of data bits is found, the original series can be modified (i.e., such that the modified series of data bits does not include the pre-determined pattern).
Consider, for example, FIG. 1 which illustrates a known system 100 including a transmitter 110. In this case, the transmitter 110 has an original series of data bits 120 to be provided to a receiver 130 (e.g., via a communication network). According to some protocols, the transmitter inserts a flag pattern 140 before and after the original series of data bits 120 before the information is transmitted to the receiver 130. By way of example, “0111 1110” flag patterns 140 are inserted before and after the original series of data bits 120 in accordance with the High Level Data Link Control (HDLC) protocol as defined by document International Organization for Standardization/International Electro-technical Commission (ISO/IEC) 13239 (2002). Note that other information may also be added to the original series of data bits 120. For example, the original series of data bits 120 might comprise a Service Data Unit (SDU) or a Protocol Data Unit (PDU) that includes HDLC header and trailer information. The receiver 130 then recognizes and removes the flag patterns 140 from the received series of data bits.
If the original series of data bits 120 happens to include the exact same pattern as the flag pattern 140, however, the receiver 130 could mistakenly interpret the received information (e.g., the receiver 130 might view the un-intentional flag pattern as an indication that the original series of data bits has ended).
To avoid this problem, the transmitter 110 can perform a “bit stuffing” operation on the original series of data bits 120. In the case of HDLC, for example, the transmitter 110 examines the original series of data bits 120 to determine if it includes five consecutive one bits (i.e., “11111”). If this pattern is found, the original series is modified by inserting an extra zero after the fifth one bit. The modified series of data bits 150 is then transmitted to the receiver 130. As a result, six consecutive one bits will not occur within the modified series of data bits 150. The receiver 130 then performs the reverse operation (i.e., removing any zero that is detected after five consecutive one bits) to re-create the original series of data bits 120.
FIG. 2 is a flow chart of a known method to perform such a bit stuffing operation. At 202, a ones counter is initialized to zero and the next data bit in the original series is determined at 204. If this data bit is not a one 206 (i.e., it is a zero), no additional zero is inserted at 208 and the process continues at 202 (and the ones counter is re-initialized to zero).
If the data bit is a one at 206, the ones counter is incremented at 210. If the ones counter does not equal five at 212 (i.e., five consecutive ones have not yet been encountered), no additional zero is inserted at 214 and the process continues at 204 (without re-initializing the ones counter). If the ones counter does equal five at 212 (i.e., five consecutive ones have now been encountered), an additional zero is inserted into the modified series of data bits at 216. The process then continues at 202 (and the ones counter is re-initialized to zero).
This bit-by-bit approach to examining an original series of data bits, however, can be time consuming and may consume a significant number of processing cycles. Moreover, the code required to perform these bit-by-bit operations can be application specific. For example, it can be difficult to modify bit stuffing code designed for one type of processor such that it can be efficiently used by another type of processor. Similarly, bit stuffing code associated with a particular protocol (e.g., code that looks for five consecutive ones in accordance with the HDLC protocol) cannot be easily modified for use with another protocol.